package com.ymatou.iapi.dglogin.testcase;

import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.AppSourceEnum;
import com.ymatou.iapi.dglogin.parameter.UserWxInfo;
import com.ymatou.iapi.dglogin.parameter.WxAuthLoginBean;
import com.ymatou.iapi.dglogin.parameter.WxLoginSession;
import com.ymatou.iapi.dglogin.service.WxAuthLoginCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.mchCreateCsBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.model.DGWxUnionidBindInfo;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*用户微信联登
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_WxAuthLogin{
	private static WxAuthLoginBean wxauthloginBean;
	private static WxAuthLoginCall wxauthloginCall;
	DGUserWapper DGUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户微信联登");
	}

	@Before
	public void caseUp() {
		wxauthloginBean=new WxAuthLoginBean();
		wxauthloginCall=new WxAuthLoginCall();
		DGUserWapper=new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(wxauthloginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(UserCreateBean usercreateBean2, Integer uid) {
		Logger.comment("验证DGUserInfo");
		DGUserInfo uinfo = DGUserWapper.selectDGUserInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getIscs() == null ? false : usercreateBean2.getIscs(), uinfo.getIsCs(), "验证IsCs");
		if(usercreateBean2.getWxAppName().equals(DGUserCallService.TestWxsqOther)) {
			Logger.verifyEquals(DGUserCallService.TestWxsqOtherSellerId, uinfo.getBelongSellerId(), "验证BelongSellerId");
		}else {
			Logger.verifyEquals(0, uinfo.getBelongSellerId(), "验证BelongSellerId");
		}
		//loginid随机生成
		Logger.verifyNotNull(uinfo.getLoginId(), "验证LoginId");
		//pwd随机生成
		Logger.verifyNotNull(uinfo.getLoginPwd(), "验证LoginPwd");
		Logger.verifyEquals(usercreateBean2.getLogoUrl(), uinfo.getLogoUrl(), "验证LogoUrl");
		if (usercreateBean2.getMobile() != null) {
			Logger.verifyEquals(usercreateBean2.getMobile(), uinfo.getMobile(), "验证Mobile");
		}
		if (usercreateBean2.getMobileAreaCode() != null) {
			Logger.verifyEquals(usercreateBean2.getMobileAreaCode(), uinfo.getMobileAreaCode(), "验证MobileAreaCode");
		}
		if (usercreateBean2.getBelongSellerId() != null) {
			Logger.verifyEquals(usercreateBean2.getBelongSellerId(), uinfo.getBelongSellerId(), "验证BelongSellerId");
		}
		Logger.verifyEquals(usercreateBean2.getNickname(), uinfo.getNickname(), "验证Nickname");
		Logger.verifyEquals(usercreateBean2.getUserGender()==null?0:usercreateBean2.getUserGender(), uinfo.getUserGender(), "验证UserGender");
		Logger.verifyEquals(usercreateBean2.getUserType()==null?0:usercreateBean2.getUserType(), uinfo.getUserType(), "验证UserType");
		Logger.verifyEquals(0, uinfo.getUserStatus(), "验证UserStatus");
		Logger.comment("验证DGUserExtInfo");
		DGUserExtInfo exinfo = DGUserWapper.selectDGUserExtInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getAppSource(), exinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getChannelSource()==null?0:usercreateBean2.getChannelSource(), exinfo.getChannelSource(), "验证ChannelSource");
		if (usercreateBean2.getClientIp() != null) {
			Logger.verifyEquals(usercreateBean2.getClientIp(), exinfo.getClientIp(), "验证ClientIp");
		}
		//这个接口没有国家编码 要商家注册接口才有
//		Logger.verifyEquals(usercreateBean2.getCountryCode(), exinfo.getCountryCode(), "验证CountryCode");
		//根据uid和oid生成设备号
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()), exinfo.getPhysicsDeviceId(), "验证DeviceId");
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()), exinfo.getLogicDeviceId(), "验证EquipmentId");
		if (usercreateBean2.getInvitationCode() != null) {
			Logger.verifyEquals(usercreateBean2.getInvitationCode(), exinfo.getInvitationCode(), "验证InvitationCode");
		}
		//目前没有remark？
		Logger.verifyEquals("", exinfo.getRemark(), "验证Remark");
		Logger.verifyEquals(usercreateBean2.getTerminalSource()==null?0:usercreateBean2.getTerminalSource(), exinfo.getTerminalSource(), "验证TerminalSource");
		Logger.comment("验证DGThirdPartyBindInfo");
		DGThirdPartyBindInfo tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(uid).get(0);
		// 多绑定关系在login站点考虑 这里主要看数据落地正确
		Logger.verifyEquals(usercreateBean2.getAppSource(), tpinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getOpenId(), tpinfo.getOpenId(), "验证OpenId");
		Logger.verifyEquals(usercreateBean2.getChannelSource()==null?0:usercreateBean2.getChannelSource(), tpinfo.getThirdPartyType(), "验证ThirdPartyType");
		if (usercreateBean2.getUnionId() != null) {
			//oid=uid 为设置uid为null后为了验证设备号而传入的设置参数
			if(!usercreateBean2.getUnionId().equals(usercreateBean2.getOpenId())) {
				Logger.verifyEquals(usercreateBean2.getUnionId(), tpinfo.getUnionId(), "验证UnionId");
			}
		}
		Logger.verifyEquals(usercreateBean2.getUserType()==null?0:usercreateBean2.getUserType(), tpinfo.getUserType(), "验证UserType");

		Logger.comment("验证DGWxUnionidBindInfo");
		List<DGWxUnionidBindInfo> wxuinfo = DGUserWapper.selectDGWxUnionidBindInfo(uid);
		if (wxuinfo.size() > 0) {
			Logger.verifyEquals(usercreateBean2.getUserType()==null?0:usercreateBean2.getUserType(), wxuinfo.get(0).getUserType(), "验证UserType");
			Logger.verifyEquals(usercreateBean2.getUnionId(), wxuinfo.get(0).getUnionId(), "验证UnionId");
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_001()  {
		Logger.start(true,"买家客服微信授权联登,普通用户");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			Map<String, Object> token = new UserTokenWapper().getUserTokenByUid(Integer.valueOf(wxauthloginCall.getString("userId")));
			Logger.comment(token.toString());
			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token.get("tSource"), "验证tSource");
			Logger.verifyEquals(u.getOpenId(),wxauthloginCall.getString("openId"), "验证openId");
			Logger.verifyEquals(u.getUnionId(),wxauthloginCall.getString("unionId"), "验证unionId");
//			verifyDB(u, uid);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_002() throws Throwable {
		Logger.start(true,"已注册买家客服微信授权联登,成功,更新最后登入时间返回token设备号");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//用户授权联登
			int userid=DGUserCallService.UserCreateCall(u);
			DGUserInfo dgUserInfo = DGUserWapper.selectDGUserInfo(userid).get(0);
			Date lt1 = dgUserInfo.getLastLoginTime();
			Thread.sleep(1000);
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			//在这个case中openid发生了变化-如果不变应该走第一个联登直接登入成功不会到这里
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			dgUserInfo = DGUserWapper.selectDGUserInfo(userid).get(0);
			Date lt2 = dgUserInfo.getLastLoginTime();
			Logger.verifyNotEquals(lt1, lt2, "更新时间");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_003() {
		Logger.start(true,"不输入loginSession失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
//			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", wxauthloginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_004() {
		Logger.start(true,"不输入iv失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
//			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", wxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_005() {
		Logger.start(true,"不输入encryptedData失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
//			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", wxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	//clientip可以为空 
	public void Tc_WxAuthLogin_006() {
		Logger.start(true,"不输入clientIp成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
//			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_007() {
		Logger.start(true,"不输入appSource失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
//			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", wxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_008() {
		Logger.start(true,"不输入terminalSource成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
//			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_009() {
		Logger.start(true,"encryptedData中没有unionid数据成功,创建新用户");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(null);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			//判断-么有unionid的情况用openid来做设备号
			u.setUnionId(u.getOpenId());
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_010() {
		Logger.start(true,"encryptedData中没有openid数据失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(null);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(null);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_011() {
		Logger.start(true,"买家客服微信授权联登,不输入WxAppName失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(null);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
//			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("false", wxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_012() {
		Logger.start(true,"买家客服微信授权联登,loginSession中unionid为空encryptedData的unionid数据库不存在,注册新用户");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			//判断-么有unionid的情况用openid来做设备号
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_013() {
		Logger.start(true,"买家客服微信授权联登,loginSession中unionid不为空openid不匹配,unionid匹配到已注册用户,绑定openid并登入成功(在其他appsource中注册)");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			Integer uid=DGUserCallService.UserCreateCall(u);
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			//这里的信息会发生变化因为绑定了2条记录
//			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			Logger.verifyEquals(uid.toString(), wxauthloginCall.getString("userId"), "验证用户相同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxAuthLogin_014() {
		Logger.start(true,"买家客服微信授权联登,loginSession中unionid为空encryptedData的unionid数据库存在,绑定openid并登入成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			Integer uid=DGUserCallService.UserCreateCall(u);
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			//这里的信息会发生变化因为绑定了2条记录
//			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			Logger.verifyEquals(uid.toString(), wxauthloginCall.getString("userId"), "验证用户相同");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_015() {
		Logger.start(true,"买家客服微信授权联登,loginSession中openid存在数据库但是和appname不匹配新注册用户");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(DGUserCallService.TestWxsqOther);
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			//这里验证一下
			u.setWxAppName(DGUserCallService.TestWxsqOther);
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 
	 */
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//客服使用新接口 接口名称	买家微信授权联登	接口地址	http://dglogin.iapi.ymatou.com/cs/wxauthlogin
	public void Tc_WxAuthLogin_016() {
		Logger.start(true,"买家客服微信授权联登,客服");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(true);
			u.setUserType(1);
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginBean.setIscs(u.getIscs());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_017() {
		Logger.start(true,"商家进行买家客服微信授权联登,商家和买家账号分离-登入成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
			Integer sellerid=DGUserCallService.UserCreateCall(u);
			//用户登入
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxauthloginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(0);
			wxauthloginBean.setIscs(false);
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			Logger.verifyNotEquals(sellerid.toString(), wxauthloginCall.getString("userId"), "创建新用户");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_018() {
		Logger.start(true,"客服进行买家客服微信授权联登,客服和买家账号分离-登入成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(true);
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册客服
			Integer sellerid=DGUserCallService.UserCreateCall(u);
			//用户登入
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxauthloginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(0);
			wxauthloginBean.setIscs(false);
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			Logger.verifyNotEquals(sellerid.toString(), wxauthloginCall.getString("userId"), "创建新用户");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//客服使用新接口 接口名称	买家微信授权联登	接口地址	http://dglogin.iapi.ymatou.com/cs/wxauthlogin
	public void Tc_WxAuthLogin_019() {
		Logger.start(true,"注册客服登入成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(true);
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册客服
			Integer sellerid=DGUserCallService.UserCreateCall(u);
			//用户登入
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			wxauthloginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(1);
			wxauthloginBean.setIscs(true);
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			Logger.verifyEquals(sellerid.toString(), wxauthloginCall.getString("userId"), "客服登入");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	//独立小程序配置 disconf->bizconfig.properties->wxAppConfig
	public void Tc_WxAuthLogin_020()  {
		Logger.start(true,"不同渠道(独立小程序)用户联登注册2个用户账号");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			String uid1 = wxauthloginCall.getString("userId");
			//设置独立小程序配置
			u.setWxAppName(DGUserCallService.TestWxsqOther);
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			String uid2 = wxauthloginCall.getString("userId");
			Logger.verifyNotEquals(uid1, uid2, "验证创建了2个用户");
//			verifyDB(u, uid);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_021()  {
		Logger.start(true,"买家客服微信授权联登,普通用户-nickname为emoji表情");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setNickname("nick1:;;;;😑😊😳");
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			Map<String, Object> token = new UserTokenWapper().getUserTokenByUid(Integer.valueOf(wxauthloginCall.getString("userId")));
			Logger.comment(token.toString());
			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token.get("tSource"), "验证tSource");
//			verifyDB(u, uid);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxAuthLogin_022()  {
		Logger.start(true,"已删除买家客服微信授权联登,普通用户-生成新用户");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			Integer u1=DGUserCallService.UserCreateCall(u);
			DGUserCallService.DeleteUser(u1);
			//新用户授权联登 等于注册
			wxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			wxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			wxauthloginBean.setEncryptedData(encryptedData);
			wxauthloginBean.setAppSource(u.getAppSource());
			wxauthloginBean.setWxAppName(u.getWxAppName());
			wxauthloginBean.setClientIp(u.getClientIp());
			wxauthloginBean.setTerminalSource(u.getTerminalSource());
			wxauthloginBean.setUserType(u.getUserType());
			wxauthloginCall.setData(wxauthloginBean);
			wxauthloginCall.callService();			
			Logger.verifyEquals("true", wxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxauthloginCall.getString("userId"), "验证uid");
			verifyDB(u, Integer.valueOf(wxauthloginCall.getString("userId")));
			Map<String, Object> token = new UserTokenWapper().getUserTokenByUid(Integer.valueOf(wxauthloginCall.getString("userId")));
			Logger.comment(token.toString());
			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token.get("tSource"), "验证tSource");
			Logger.verifyNotEquals(u1.toString(),wxauthloginCall.getString("userId"), "验证生成的是新用户号");
//			verifyDB(u, uid);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}